<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform" size="mini">
      <div>
        <el-form-item label="工厂名称/吊牌编码" class="myform-item">
          <el-input v-model="form.title" placeholder="请输入工厂名称/吊牌编码" @keyup.enter.native="onSearch" clearable></el-input>
        </el-form-item>
        <el-form-item label="启用/禁用" class="myform-item">
          <el-select v-model="form.status" placeholder="请选择">
            <el-option label="全部" value=""> </el-option>
            <el-option v-for="item in optionsD" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推送状态" class="myform-item">
          <el-select v-model="form.is_oms" placeholder="请选择">
            <el-option label="全部" value=""> </el-option>
            <el-option v-for="item in optionsOMS" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="合同类型" class="myform-item">
          <el-select v-model="form.is_advance" placeholder="请选择">
            <el-option label="全部" value=""> </el-option>
            <el-option v-for="item in optionsYY" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="E签宝状态" class="myform-item">
          <el-select v-model="form.sing_status_eqb" placeholder="请选择">
            <el-option label="全部" value=""> </el-option>
            <el-option v-for="item in optionsEQB" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 39px">
          <el-button type="primary" @click="onSearch">查询</el-button>
          <el-button @click="onCreateFactory">新建工厂</el-button>
          <!-- <el-button type="primary">上传文件</el-button> -->
        </el-form-item>
      </div>
    </el-form>
    <el-tabs v-model="form.type" @tab-click="handleClick">
      <el-tab-pane v-for="item in tabpanes" :key="item.group" :label="item.title" :name="item.group">
        <el-table :data="tableData" style="width: 100%" border>
          <el-table-column label="工厂名称" align="center" prop="factory_name"></el-table-column>
          <el-table-column label="工厂编码" align="center" prop="supplier_id"></el-table-column>
          <el-table-column label="状态" align="center" prop="status">
            <template slot-scope="{ row }">
              <div :style="{ color: row.status == 1 ? 'red' : '#67C23A' }">
                {{ row.status == 1 ? "未启用" : "已启用" }}
              </div>
              <div :style="{ color: row.is_oms == 1 ? '#67C23A' : '' }">
                {{ row.is_oms == 0 ? "未推送" : "已推送" }}
              </div>
            </template>
          </el-table-column>

          <el-table-column label="吊牌编号" align="center" prop="tag_number"></el-table-column>
          <el-table-column label="简称" align="center" prop="factory_name_jiancheng"></el-table-column>
          <el-table-column label="工厂类别" align="center" prop="group_name"></el-table-column>
          <el-table-column label="合同类型" align="center" prop="is_advance">
            <template slot-scope="{ row }">
              <div :style="{ color: row.is_advance == 1 ? '#67C23A' : '' }">
                {{ row.is_advance == 1 ? "有预付款" : "无预付款" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="泰安e签宝" align="center" prop="sing_status_eqb">
            <template slot-scope="{ row }">
              <div :style="{ color: row.sing_status_eqb == 1 ? '#67C23A' : '' }">
                {{ row.sing_status_eqb == 1 ? "已开通" : "未开通" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="快哉-e签宝" align="center" prop="kz_sing_status_eqb">
            <template slot-scope="{ row }">
              <div :style="{ color: row.kz_sing_status_eqb == 1 ? '#67C23A' : '' }">
                {{ row.kz_sing_status_eqb == 1 ? "已开通" : "未开通" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="有香如故-e签宝" align="center" prop="kz_sing_status_eqb">
            <template slot-scope="{ row }">
              <div :style="{ color: row.yxrg_sing_status_eqb == 1 ? '#67C23A' : '' }">
                {{ row.yxrg_sing_status_eqb == 1 ? "已开通" : "未开通" }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="{ row }">
              <span v-if="row.status == 0">
                <el-button type="text" size="default" @click="onEdit(row)">编辑</el-button>
                <el-button type="text" size="default" @click="onUserList(row)">用户列表</el-button>
                <!-- <el-button type="text" size="default" @click="onEditCode(row)"
              >吊牌编号</el-button
            > -->
                <!-- <el-button type="text" size="default" @click="onAddUser(row)"
              >添加用户</el-button
            > -->
                <!-- <el-button type="text" size="default" @click="onEdit(row)"
              >合同/银行信息</el-button
            > -->
                <el-button type="text" size="default" @click="onEQB(row)"
                  v-if="row.sing_status_eqb == 0">开通e签宝</el-button>
                <el-button type="text" size="default" @click="onEQBYXRG(row)"
                  v-if="row.yxrg_status_eqb == 0 || row.yxrg_status_eqb == null">开通e签宝-有香如故</el-button>
                <el-button type="text" size="default" @click="onEQB(row)" v-if="row.sing_status_eqb == 1"
                  style="color: #e6a23c">e签宝信息</el-button>
                <el-button type="text" size="default" @click="onPush(row)">推送</el-button>
              </span>
              <el-button type="text" style="color: red; margin-left: 10px" @click="onDisable(row.supplier_id, 1)"
                v-if="row.status == 0">禁用</el-button>
              <el-button type="text" style="margin-left: 10px" @click="onDisable(row.supplier_id, 0)"
                v-if="row.status != 0">启用</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <pagination :form="form" :total="total" @paginationPostOrderTaskList="postHomeCodeGetFactory" />

    <el-dialog title="添加工厂用户" :visible.sync="dialogVisible" width="30%" :close-on-click-modal="false">
      <el-form ref="userForm" :model="userForm" :rules="rules">
        <el-form-item label="工厂名称" class="myform-item">
          <el-input v-model="userForm.factory_name" placeholder="请输入工厂名称" readonly></el-input>
        </el-form-item>
        <el-form-item label="工厂用户名" class="myform-item" prop="name">
          <el-input v-model="userForm.name" placeholder="请输入工厂用户名"></el-input>
        </el-form-item>
        <el-form-item label="手机号" class="myform-item" prop="phone">
          <el-input type="number" v-model="userForm.phone" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 100%; margin: 30px 0" @click="onAddUserPup('userForm')"
            :loading="loading">添加</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="工厂信息" :visible.sync="dialogVisibleInfo" width="1100px" :close-on-click-modal="false">
      <el-form ref="infoForm" :model="infoForm" :rules="infoFormrules" label-position="right" label-width="120px"
        class="infoFormOne">
        <div>
          <div class="line">基本信息</div>
          <div class="infoFormOne-one">
            <el-form-item label="工厂名称" prop="factory_name">
              <el-input v-model="infoForm.factory_name" placeholder="请输入工厂名称" style="width: 200px" size="mini"></el-input>
            </el-form-item>
            <el-form-item label="简称">
              <el-input v-model="infoForm.factory_name_jiancheng" placeholder="请输入简称" style="width: 200px"
                size="mini"></el-input>
            </el-form-item>
            <el-form-item label="工厂类别" prop="groups">
              <el-select v-model="infoForm.groups" placeholder="请选择" style="width: 200px" size="mini">
                <el-option v-for="item in factorys" :key="item.group" :label="item.title" :value="item.group">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="合同类型" prop="is_advance">
              <el-select v-model="infoForm.is_advance" placeholder="请选择" style="width: 200px" size="mini">
                <el-option v-for="item in optionsYY" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="吊牌编码">
              <el-input v-model="infoForm.tag_number" placeholder="请输入吊牌编码" style="width: 200px" size="mini"></el-input>
            </el-form-item>
            <el-form-item label="拼音简称">
              <el-input v-model="infoForm.pinyin_name" placeholder="请输入吊牌编码" style="width: 200px" size="mini"></el-input>
            </el-form-item>
            <el-form-item label="Qc免检">
              <el-radio-group v-model="infoForm.is_free">
                <el-radio label="0">否</el-radio>
                <el-radio label="1">是</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
        </div>
        <div>
          <div class="line">合同/银行信息</div>
          <div class="infoFormOne-one">
            <el-form-item label="公司资质" class="myform-item" prop="company_qualification">
              <el-select v-model="infoForm.company_qualification" placeholder="请选择" style="width: 200px" size="mini">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="公司抬头" class="myform-item" prop="company_head">
              <el-input v-model="infoForm.company_head" placeholder="请输入公司抬头" style="width: 200px" size="mini"></el-input>
            </el-form-item>
            <el-form-item label="开户行" class="myform-item" prop="bank_of_deposit">
              <el-input v-model="infoForm.bank_of_deposit" placeholder="请输入开户行" style="width: 200px"
                size="mini"></el-input>
            </el-form-item>
            <el-form-item label="开户行号" class="myform-item" prop="opening_bank_no">
              <el-input v-model="infoForm.opening_bank_no" placeholder="请输入开户行号" style="width: 200px"
                size="mini"></el-input>
            </el-form-item>
            <el-form-item label="银行账户" class="myform-item" prop="bank_account">
              <el-input v-model="infoForm.bank_account" placeholder="请输入银行账户" style="width: 200px" size="mini"></el-input>
            </el-form-item>
            <el-form-item label="开票税率(专票)" class="myform-item" prop="tax_rate">
              <el-input type="number" v-model="infoForm.tax_rate" placeholder="请输入专票税率（单位 %）" style="width: 200px"
                size="mini"></el-input>
            </el-form-item>
            <el-form-item label="法定代表" class="myform-item" prop="legal_person">
              <el-input v-model="infoForm.legal_person" placeholder="请输入法定代表" style="width: 200px" size="mini"></el-input>
            </el-form-item>
            <el-form-item label="联系电话" class="myform-item" prop="contact_phone">
              <el-input v-model="infoForm.contact_phone" placeholder="请输入联系电话" style="width: 200px"
                size="mini"></el-input>
            </el-form-item>
            <el-form-item label="联系地址" class="myform-item" prop="contact_address">
              <el-input v-model="infoForm.contact_address" placeholder="请输入联系地址" style="width: 200px"
                size="mini"></el-input>
            </el-form-item>
          </div>
        </div>

        <el-form-item label="营业执照" class="myform-item" prop="business_license">
          <el-upload class="avatar-uploader" action="/" :before-upload="beforeAvatarUpload">
            <img v-if="infoForm.business_license" :src="infoForm.business_license" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="onAddInfoPup('infoForm')" :loading="loading">保 存</el-button>
      </span>
    </el-dialog>
    <el-dialog title="e签宝信息" :visible.sync="dialogVisibleInfoE" width="30%" :close-on-click-modal="false">
      <el-form ref="infoFormE" :model="infoFormE" :rules="infoFormErules">
        <el-form-item label="公司抬头" class="myform-item" prop="company_head">
          <el-input v-model="infoFormE.company_head" disabled></el-input>
        </el-form-item>
        <el-form-item label="企业证件号（税号）" class="myform-item" prop="certificate_no">
          <el-input v-model="infoFormE.certificate_no" placeholder="请输入企业证件号（税号）"
            :disabled="sing_status_eqb == 1"></el-input>
        </el-form-item>
        <el-form-item label="姓名" class="myform-item" prop="eqb_user">
          <el-input v-model="infoFormE.eqb_user" placeholder="请输入姓名" :disabled="sing_status_eqb == 1"></el-input>
        </el-form-item>
        <el-form-item label="手机号码" class="myform-item" prop="eqb_phone">
          <el-input type="number" v-model="infoFormE.eqb_phone" placeholder="请输入手机号码"
            :disabled="sing_status_eqb == 1"></el-input>
        </el-form-item>
        <el-form-item label="身份证号码" class="myform-item" prop="eqb_card">
          <el-input v-model="infoFormE.eqb_card" placeholder="请输入身份证号码" :disabled="sing_status_eqb == 1"></el-input>
        </el-form-item>
        <el-form-item v-if="sing_status_eqb == 0">
          <el-button type="primary" style="width: 100%; margin: 30px 0" @click="onAddInfoPupE('infoFormE')"
            :loading="loading">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="吊牌编号" :visible.sync="dialogVisibleInfoGcode" width="30%" :close-on-click-modal="false">
      <el-form ref="infoFormGcode" :model="infoFormGcode" :rules="infoFormGcode" label-position="left"
        label-width="120px">
        <el-form-item label="工厂名称" class="myform-item">
          <el-input readonly v-model="infoFormGcode.factory_name" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="吊牌编号" class="myform-item">
          <el-input placeholder="请输入吊牌编号" v-model="infoFormGcode.tag_number" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 300px; margin: 30px 0" @click="onAddInfoPupGcode" :loading="loading"
            :disabled="!infoFormGcode.tag_number">保 存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  postHomeCodeGetFactory,
  postAdminCodeAddFactoryUser,
  postAdmincodesetFactoryinfo,
  postAdminPricingOpen_eqb,
  uploadHomeApiupload,
  postAdminOmsaddSupplier_synchronize,
  postAdmincodesetFactoryTag,
  postAdminCodeSetFactoryinfotovoid,
  postAdminPricingOpen_eqb_yxrg
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      dialogVisibleInfo: false,
      dialogVisibleInfoE: false,
      dialogVisibleInfoGcode: false,
      sing_status_eqb: 0,
      activeName: "",
      tabpanes: [
        {
          title: "全部",
          group: "",
        },
        {
          title: "成衣厂",
          group: "1",
        },
        {
          title: "绣花厂",
          group: "2",
        },
        {
          title: "烫金厂",
          group: "5",
        },
        {
          title: "印花厂",
          group: "6",
        },
        {
          title: "赠品供应商",
          group: "7",
        },
        {
          title: "物料厂",
          group: "8",
        },
      ],
      factorys: [
        {
          title: "成衣厂",
          group: "1",
        },
        {
          title: "绣花厂",
          group: "2",
        },
        {
          title: "烫金厂",
          group: "5",
        },
        {
          title: "印花厂",
          group: "6",
        },
        {
          title: "赠品供应商",
          group: "7",
        },
        {
          title: "物料厂",
          group: "8",
        },
      ],
      optionsD: [
        {
          value: "0",
          label: "启用",
        },
        {
          value: "1",
          label: "禁用",
        },
      ],
      optionsOMS: [
        {
          value: "0",
          label: "未推送",
        },
        {
          value: "1",
          label: "已推送",
        },
      ],
      optionsEQB: [
        {
          value: "0",
          label: "未开通",
        },
        {
          value: "1",
          label: "已开通",
        },
      ],
      optionsYY: [
        {
          value: "0",
          label: "无预付款",
        },
        {
          value: "1",
          label: "有预付款",
        },
      ],
      options: [
        {
          value: "小规模",
          label: "小规模",
        },
        {
          value: "一般纳税人",
          label: "一般纳税人",
        },
      ],
      form: {
        // factory_name: "",
        status: "",
        is_oms: "",
        sing_status_eqb: "",
        is_advance: "",
        type: "",
        page: 1,
        size: 10,
      },
      userForm: {
        fid: "",
        name: "",
        phone: "",
        factory_name: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入工厂用户名", trigger: "blur" },
        ],
        phone: [{ required: true, message: "请输入手机号", trigger: "blur" }],
      },
      infoForm: {
        factory_name_jiancheng: "", // 工厂简称 factory_name_jiancheng
        factory_name: "", // 工厂名称 factory_name
        group: "", // 工厂类型 1成衣厂 2绣花厂 5烫金厂6印花厂7赠品供应商8物料厂 groups
        is_advance: "", // 1 需要预付 0 不需要预 空值全部 is_advance
        tag_number: "", // 吊牌编号 tag_number
        company_qualification: "", // 公司资质 company_qualification
        company_head: "", // 公司抬头 company_head
        bank_of_deposit: "", // 开户行 bank_of_deposit
        opening_bank_no: "", // 开户行号 opening_bank_no
        bank_account: "", // 银行账户 bank_account
        legal_person: "", //法定代表 legal_person
        contact_phone: "", //联系电话 contact_phone
        contact_address: "", //联系地址 contact_address
        tax_rate: "", // 税率 tax_rate
        business_license: "", // 图片 business_license
        pinyin_name: "", // 拼音简称
        is_free: "0",
      },
      infoFormrules: {
        factory_name: [
          { required: true, message: "请输入工厂名称", trigger: "blur" },
        ],
        groups: [
          { required: true, message: "请选择工厂类别", trigger: "blur" },
        ],
        is_advance: [
          { required: true, message: "请选择合同类型", trigger: "blur" },
        ],
        company_qualification: [
          { required: true, message: "请选择公司资质", trigger: "blur" },
        ],
        company_head: [
          { required: true, message: "请输入公司抬头", trigger: "blur" },
        ],
        bank_of_deposit: [
          { required: true, message: "请输入开户行", trigger: "blur" },
        ],
        opening_bank_no: [
          { required: true, message: "请输入开户行号", trigger: "blur" },
        ],
        bank_account: [
          { required: true, message: "请输入银行账户", trigger: "blur" },
        ],
        tax_rate: [
          {
            required: true,
            message: "请输入专票税率（单位 %）",
            trigger: "blur",
          },
        ],
        legal_person: [
          { required: true, message: "请输入法定代表", trigger: "blur" },
        ],
        contact_phone: [
          { required: true, message: "请输入联系电话", trigger: "blur" },
        ],
        contact_address: [
          { required: true, message: "请输入联系地址", trigger: "blur" },
        ],
        business_license: [
          { required: true, message: "请上传图片", trigger: "blur" },
        ],
      },
      infoFormE: {
        supplier_id: "",
        company_head: "", // 公司抬头
        certificate_no: "", //企业证件号（税号）
        eqb_user: "", //姓名
        eqb_phone: "", //手机号码
        eqb_card: "", // 身份证
      },
      infoFormErules: {
        certificate_no: [
          {
            required: true,
            message: "请输入企业证件号（税号）",
            trigger: "blur",
          },
        ],
        eqb_user: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        eqb_phone: [
          { required: true, message: "请输入手机号码", trigger: "blur" },
        ],
        eqb_card: [
          { required: true, message: "请输入身份证", trigger: "blur" },
        ],
      },
      infoFormGcode: {},
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;
    this.postHomeCodeGetFactory(form);
  },
  methods: {
    // 用户列表
    onUserList(row) {
      this.$router.push({
        name: "PlantUserListOne",
        query: { name: row.factory_name, id: row.id },
      });
    },
    handleClick(tab, event) {
      console.log(tab, event);
      let { form } = this;
      form.group = tab.name;
      form.page = 1;
      this.postHomeCodeGetFactory(form);
    },
    async onDisable(supplier_id, type) {
      let data = {
        supplier_id,
      };
      this.$confirm(
        `此操作将${type == 1 ? "禁用" : "启用"}该工厂, 是否继续?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(async () => {
          try {
            await postAdminCodeSetFactoryinfotovoid(data);
            this.$message.success("成功");
            let form = this.form;
            this.postHomeCodeGetFactory(form);
          } catch (error) { }
        })
        .catch(() => { });
    },
    async onAddInfoPupGcode() {
      let { infoFormGcode } = this;
      let obj = {
        supplier_id: infoFormGcode.supplier_id,
        tag_number: infoFormGcode.tag_number,
      };
      this.infoFormGcode.tag_number = "";
      try {
        await postAdmincodesetFactoryTag(obj);
        let form = this.form;
        this.postHomeCodeGetFactory(form);
        this.dialogVisibleInfoGcode = false;
      } catch (error) { }
    },
    onEditCode(row) {
      this.infoFormGcode = {
        supplier_id: row.supplier_id,
        tag_number: row.tag_number,
        factory_name: row.factory_name,
      };
      this.dialogVisibleInfoGcode = true;
    },
    onPush(row) {
      let obj = {
        supplier_id: row.supplier_id,
        action_type: "add",
      };
      let form = this.form;
      this.$confirm(`确定推送OMS?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminOmsaddSupplier_synchronize(obj).then((res) => {
            this.$message({
              type: "success",
              message: "推送成功",
            });
            this.postHomeCodeGetFactory(form);
          });
        })
        .catch(() => {
          // this.$message({
          //   type: "info",
          //   message: "已取消推送",
          // });
        });
    },
    beforeAvatarUpload(file) {
      this.file = file;
      let reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = () => {
        let _base64 = reader.result;
        this.infoForm.business_license = _base64;
      };
      return false;
    },
    async onAddInfoPupE(formName) {
      let that = this;
      let data = {
        supplier_id: this.infoFormE.supplier_id,
      };
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          this.loading = true;
          let infoFormE = that.infoFormE;
          await postAdmincodesetFactoryinfo(infoFormE)
            .then(async (res) => {
              await postAdminPricingOpen_eqb(data);
              let form = this.form;
              this.$message.success("开通成功");
              this.postHomeCodeGetFactory(form);
              this.dialogVisibleInfoE = false;
              this.loading = false;
            })
            .catch((err) => {
              this.loading = false;
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    async onEQB(e) {
      let that = this;
      this.infoFormE.supplier_id = e.supplier_id;
      this.sing_status_eqb = Number(e.sing_status_eqb);
      if (e.company_head) {
        this.infoFormE = {
          supplier_id: e.supplier_id,
          company_head: e.company_head, //公司抬头
          certificate_no: e.certificate_no, //企业证件号（税号）
          eqb_user: e.eqb_user, // 姓名
          eqb_phone: e.eqb_phone, // 手机号码
          eqb_card: e.eqb_card, // 身份证
        };
        that.dialogVisibleInfoE = true;
      } else {
        this.$message.warning("请先填写 合同/银行信息");
      }
    },
    async onEQBYXRG(e) {
      let that = this;
      this.$confirm('确定开通E签宝-有香如故?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        let data = {
          supplier_id: e.supplier_id
        }
        await postAdminPricingOpen_eqb_yxrg(data)
        this.$message({
          type: 'success',
          message: '开通成功!'
        });
      }).catch(() => {
      });
    },
    // 采购列表
    async postHomeCodeGetFactory(data) {
      this.loading = true;
      if (data.type == 0) {
        data.type = "";
      }
      this.form = data;
      postHomeCodeGetFactory(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
      if (data.type == "") {
        data.type = "0";
      }
    },
    onAddInfoPup(formName) {
      let that = this;
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          console.log("valid", valid);
          this.loading = true;
          let infoForm = that.infoForm;
          let http = infoForm.business_license.substr(0, 4);
          if (http != "http") {
            await uploadHomeApiupload(this.file).then((res) => {
              console.log("图片");
              infoForm.business_license = res.img;
            });
          }

          await postAdmincodesetFactoryinfo(infoForm)
            .then((res) => {
              let form = this.form;
              this.$message.success("保存成功");
              this.postHomeCodeGetFactory(form);
              this.dialogVisibleInfo = false;
              this.loading = false;
            })
            .catch((err) => {
              this.loading = false;
            });
        } else {
          this.loading = false;
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 添加工厂用户
    onAddUserPup(formName) {
      let that = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true;
          postAdminCodeAddFactoryUser(that.userForm).then((res) => {
            this.dialogVisible = false;
            this.loading = false;
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 弹出层 - 添加工厂用户
    onAddUser(e) {
      this.userForm = {
        fid: e.id,
        name: "",
        phone: "",
        factory_name: e.factory_name,
      };
      this.dialogVisible = true;
    },
    // 弹出层 - 编辑信息
    onEdit(e) {
      this.infoForm.supplier_id = e.supplier_id;
      this.infoForm = {
        id: e.id,
        supplier_id: e.supplier_id,
        factory_name_jiancheng: e.factory_name_jiancheng,
        factory_name: e.factory_name,
        groups: e.group,
        is_advance: e.is_advance,
        tag_number: e.tag_number,
        pinyin_name: e.pinyin_name,
        is_free: e.is_free,
        company_qualification: e.company_qualification, //公司资质
        company_head: e.company_head, // 公司抬头
        bank_of_deposit: e.bank_of_deposit, // 开户行
        opening_bank_no: e.opening_bank_no, // 开户行号
        bank_account: e.bank_account, // 银行账户
        tax_rate: e.tax_rate, // 税率
        legal_person: e.legal_person, // 法定代表
        contact_phone: e.contact_phone, // 联系电话
        contact_address: e.contact_address, // 联系地址
        business_license: e.business_license, // 营业执照
      };

      this.dialogVisibleInfo = true;
    },
    // 新建工厂
    onCreateFactory() {
      this.infoForm = {
        factory_name_jiancheng: "",
        factory_name: "",
        groups: "",
        is_advance: "",
        tag_number: "",
        company_qualification: "", // 公司资质
        company_head: "", // 公司抬头
        bank_of_deposit: "", // 开户行
        opening_bank_no: "", // 开户行号
        bank_account: "", // 银行账户
        legal_person: "", //法定代表
        contact_phone: "", //联系电话
        contact_address: "", //联系地址
        tax_rate: "", // 税率
        business_license: "", // 图片
        pinyin_name: "",
        is_free: "0",
      };
      this.dialogVisibleInfo = true;
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postHomeCodeGetFactory(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.infoFormOne {
  .infoFormOne-one {
    display: flex;
    flex-wrap: wrap;

    /deep/ .el-form-item {
      width: 320px;
    }
  }
}

.myform {
  display: flex;
  justify-content: space-between;

  >div {
    display: flex;
  }

  &-item {
    margin-right: 10px;
  }
}

.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
